package com.prs.crm.action.project;

import java.io.File;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;

import com.prs.crm.annotation.Clew;
import com.prs.crm.context.AppContext;
import com.prs.crm.domain.flow.FlowVerifyDetail;
import com.prs.crm.domain.project.Task;
import com.prs.crm.exception.InValidException;
import com.prs.crm.service.project.TaskService;

/**
 * 任务审核
 * @author Administrator
 *
 */
public class TaskVerifyAction extends BaseAction{

	private static final long serialVersionUID = 1L;

	private TaskService taskService;
	
	private FlowVerifyDetail detail;
	
	private Task task;
	
	private PaginationSupport page;
	
	private File upload;
	
	private String uploadFileName;
	

	private File[] uploads;
	
	private String[] uploadsFileName;

	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public TaskService getTaskService() {
		return taskService;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public Task getTask() {
		return task;
	}

	public void setUploads(File[] uploads) {
		this.uploads = uploads;
	}

	public File[] getUploads() {
		return uploads;
	}

	public void setUploadsFileName(String[] uploadsFileName) {
		this.uploadsFileName = uploadsFileName;
	}

	public String[] getUploadsFileName() {
		return uploadsFileName;
	}

	public void setDetail(FlowVerifyDetail detail) {
		this.detail = detail;
	}

	public FlowVerifyDetail getDetail() {
		return detail;
	}

	public void setPage(PaginationSupport page) {
		this.page = page;
	}

	public PaginationSupport getPage() {
		return page;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public File getUpload() {
		return upload;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}
	
	
	@Action("prepareSubmitTask")
	public String prepareSubmitTask()
	{
		
		return SUCCESS;
	}
	
	@Clew(results={"success"})
	@Action(value="submitTask",results={@Result(name="success",type="redirect",location="executeTask?task=${task.id}"),
			@Result(name="error",type="chain",location="prepareSubmitTask")})
	public String submitTask()
	{
		try
		{
			this.getTaskService().submitTask(task, uploads, uploadsFileName);
			this.setPrompt("提交成功");
			return SUCCESS;
		}
		catch (InValidException e)
		{
			this.addActionError(e.getMessage());
			return ERROR;
		}
	}
	
	@Action("listVerifyTask")
	public String listVerifyTask()
	{
		this.setPage(this.getTaskService().listProcessEntitys(this.getPaginationHelper().prepare(page)
							, AppContext.getAccountContext().currentUser()));
		return SUCCESS;
	}
	

	
	@Action("verifyTask")
	public String verifyTask()
	{
		return SUCCESS;
	}
	
	@Clew(results={"success"})
	@Action(value="saveTaskVerify",results={@Result(name="success",type="redirect",location="listVerifyTask")})
	public String saveTaskVerify()
	{
		this.getTaskService().executeVerify(task, detail,
					AppContext.getAccountContext().currentUser(), upload, uploadFileName);
		this.setPrompt("审核成功");
		return SUCCESS;
	}

	/**
	 * 列出审核历史
	 * @return
	 */
	@Action("listTaskVerifyHistory")
	public String listTaskVerifyHistory()
	{
		this.setPage(this.getTaskService().listVerifyTaskHistory(this.getPaginationHelper().prepare(page)
				, AppContext.getAccountContext().currentUser()));
		return SUCCESS;
	}
	
	/**
	 * 列出审核信息
	 * @return
	 */
	@Action("listTaskVerifyDetail")
	public String listTaskVerifyDetail()
	{
		return SUCCESS;
	}
	
	
	/**
	 * 查看任务的详细审核信息
	 */
	@Action("viewTaskVerifyDetail")
	public String viewTaskVerifyDetail()
	{
		return SUCCESS;
	}
	
	
}
